import { WeaSearchGroup, WeaFormItem } from 'ecCom';
import { WeaSwitch } from 'comsMobx';
import { Button, Form } from 'antd';
import { toJS } from "mobx"
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

class Condition extends React.Component {

  constructor(props){
      super(props);
      this.formParams = {};
  }

  render() {
    const { condition, form } = this.props.listStore;
    const {onEnterSearch} = this.props;
    const { isFormInit } = form;
    let group = [];
    const formParamsTemp = form.getFormParams();
    for(let param in formParamsTemp){
        this.formParams[param] = formParamsTemp[param];
    }
    isFormInit && condition.map((c,i) => {
      let items = [];
      c.items.map(fields => {
        items.push({
          com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@32o9wg@${fields.domkey[0]}`}
            label={`${fields.label}`}
            labelCol={{ span: `${fields.labelcol}` }}
            wrapperCol={{ span: `${fields.fieldcol}` }}>
            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@klft4z@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams} onEnterSearch={onEnterSearch} />
          </WeaFormItem>),
          colSpan: 1
        })
      });
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@7dfvhc@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items} />)
    });
    return group;
  }
}

const getAdButtons = (listStore) => {
  const { doSearch, setShowSearchAd, clearFormFields, setConditionByTree } = listStore;
  return [
    (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ft9ma0@search`} type="primary" onClick={() => { doSearch(); setShowSearchAd(false); }}>{getLabel(197,"搜索")}</Button>),
    (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@0dltqr@reset`} type="ghost" onClick={() => { clearFormFields(); setConditionByTree(); }}>{getLabel(2022,"重置")}</Button>),
    (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@qjq6dp@close`} type="ghost" onClick={() => { setShowSearchAd(false) }}>{getLabel(201,"取消")}</Button>)
  ];
}

export { Condition, getAdButtons }
